//
//  BeeGroupManager.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/13.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "BeeGroupManager.h"

@interface BeeGroupManager()
{
    BOOL inRequest;
}

@end

@implementation BeeGroupManager

+(instancetype)sharedManager
{
    static dispatch_once_t queue;
    static BeeGroupManager * manager = nil;
    
    dispatch_once(&queue, ^{
        manager = [[BeeGroupManager alloc]init];
    });
    
    return manager;
}

-(instancetype)init
{
    self = [super init];
    
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinBeeGroup:) name:Notification_JoinBeeGroup object:nil];
    }
    
    return self;
}


-(void)joinBeeGroup:(NSNotification *)nitific
{
    //后期考虑处理请求队列
    if (inRequest) {
        return;
    }
    
    //检查登录状态
    if (![UserInfoManager sharedManager].isLogin) {
        
        [[JumpManager sharedManager] jumpToLogin];
        
        return;
    }
    
    //检查钱包
    if (![UserInfoManager sharedManager].haveWallet) {
        
        [[JumpManager sharedManager] jumpToBeeWalletAdd];
        
        return;
    }
    
    NSString *gid = SafeGetStringValue([nitific object]);
    
    [self post:BeeGroupJoin_URL param:@{@"uid":[UserInfoManager sharedManager].userId,@"gid":gid} code:BeeGroupJoin_URL_Code];
    
}

#pragma mark - response

-(void)requestSuccess:(id)data code:(NSInteger)code
{
    NSString *info = SafeGetStringValue([data objectForKey:@"msg"]);
    [NoticePopHelper showNoticeText:info];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:Notification_JoinBeeGroupSuccess object:nil];
    
    inRequest = NO;
}

-(void)requestLogicError:(id)data code:(NSInteger)code
{
    [super requestLogicError:data code:code];
    inRequest = NO;
}

-(void)requestFailure:(NSError *)error code:(NSInteger)code
{
    inRequest = NO;
}

@end
